//
//  MainVC.m
//  OrderDish
//
//  Created by mac on 16/11/25.
//  Copyright © 2016年 LiWenqing. All rights reserved.
//

#import "MainVC.h"
#import "LanguageVC.h"
#import "LeftVC.h"
@interface MainVC ()<UITableViewDataSource,UITableViewDelegate>
{
    __weak IBOutlet UIButton *_exitBtn;

    __weak IBOutlet UITableView *_rightTableV;
    NSArray *_grouparray;
    NSInteger _selectRow;
}
@end

@implementation MainVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    _grouparray = [[NSArray alloc]initWithArray:[DatabaseTool selectGroupFromGroupTable]];

    _selectRow=0;
    _rightTableV.dataSource=self;
    _rightTableV.delegate=self;
    _rightTableV.rowHeight=_rightTableV.frame.size.height/7;
    _rightTableV.backgroundColor=[UIColor clearColor];
    
    [_rightTableV registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
    for (int i=0; i<7; i++) {
        LeftVC *lvc=[[LeftVC alloc]init];
        [self addChildViewController:lvc];
    }
    LeftVC *lvc=[self.childViewControllers objectAtIndex:0];
    [self.view addSubview:lvc.view];
    [self.view bringSubviewToFront:_rightTableV];
    [self.view bringSubviewToFront:_exitBtn];
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _grouparray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
  
    GroupModel *group=_grouparray[indexPath.row];
 
//    cell.textLabel.text=@"123";
    if (_selectRow == indexPath.row) {
        cell.imageView.image=[UIImage imageNamed:group.hImg];
    }else{
        cell.imageView.image=[UIImage imageNamed:group.img];
    }
    cell.backgroundColor=[UIColor clearColor];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    _selectRow=indexPath.row;
    [_rightTableV reloadData];
    LeftVC *lvc=[self.childViewControllers objectAtIndex:indexPath.row];
    lvc.index=_selectRow;
    [self.view addSubview:lvc.view];
    [self.view bringSubviewToFront:_rightTableV];
    [self.view bringSubviewToFront:_exitBtn];
}
- (IBAction)exit:(id)sender {
    LanguageVC *lvc=[[LanguageVC alloc]init];
    [CommomTool transformWithViewController:lvc];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
